package cd.safe.school.adapter;

import java.util.List;
import java.util.Map;

import android.content.Context;
import android.content.Intent;
import android.os.Handler;
import android.sax.StartElementListener;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ListView;
import android.widget.TextView;
import cd.safe.school.R;
import cd.safe.school.activity.SchoolSMS;
import cd.safe.school.activity.SchoolSMS_detail;
import cd.safe.school.bean.ChatTuisong;
import cd.safe.school.bean.Msg;

public class SchoolSMSAdapter extends BaseAdapter {
	private List<Msg> lists;
	private Context context;
	private Handler handler;

	public SchoolSMSAdapter(Context context, List<Msg> lists, Handler handler) {
		this.context = context;
		this.lists = lists;
		this.handler = handler;

	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return lists.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		LayoutInflater in = LayoutInflater.from(context);
		if (lists.get(position).isFlag()) {

			convertView = in.inflate(R.layout.school_sms_item_03, null);

			TextView time = (TextView) convertView.findViewById(R.id.sms_time);
			TextView name = (TextView) convertView.findViewById(R.id.sms_name);
			TextView content = (TextView) convertView
					.findViewById(R.id.sms_content);
			time.setText(lists.get(position).getCreatetime());
			name.setText(String.valueOf(lists.get(position).getMsgid()));
			content.setText(lists.get(position).getMsgcontent());

		} else {

			convertView = in.inflate(R.layout.school_sms_item_02, null);

			TextView person_biaoti = (TextView) convertView
					.findViewById(R.id.person_biaoti02);
			TextView time = (TextView) convertView.findViewById(R.id.time02);
			TextView person_xinxiji = (TextView) convertView
					.findViewById(R.id.person_xinxiji02);
			person_biaoti.setText(String
					.valueOf(lists.get(position).getMsgid()));
			time.setText((CharSequence) lists.get(position).getCreatetime());
			person_xinxiji.setText((CharSequence) lists.get(position)
					.getMsgcontent());
		}

		return convertView;
	}

	@Override
	public void notifyDataSetChanged() {

		super.notifyDataSetChanged();
		handler.sendEmptyMessage(1);
	}

}
